
package com.amado.springboot.springbootcms.service.impl;

import com.amado.springboot.springbootcms.domain.Depa;
import com.amado.springboot.springbootcms.domain.User;
import com.amado.springboot.springbootcms.mapper.DepaMapper;
import com.amado.springboot.springbootcms.mapper.UserMapper;
import com.amado.springboot.springbootcms.service.DepaService;
import com.amado.springboot.springbootcms.util.RedisTemplateDriver;
import com.amado.springboot.springbootcms.vo.UserLoginVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wangyl-910
 * @description
 * @date 2017/12/4
 * @see
 */
@Service
public class DepaServiceImpl implements DepaService {

    Logger logger = LoggerFactory.getLogger(DepaServiceImpl.class);
    @Autowired
    private RedisTemplateDriver redisTemplateDriver;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private DepaMapper depaMapper;


    @Override
    public void addDepa(Depa depa) {
        if(depa!=null){
            if("".equals (depa.getDepaName ())&&"".equals (depa.getAddress ())){
                logger.debug("返回值" );
            }else{
                depaMapper.insertSelective(depa);
            }
        }

    }

    @Override
    public void deleteDepa(List<Long> id) {
        depaMapper.delete(id);
    }


    @Override
    public Depa get(Long id) {
        Depa depa = new Depa();
        if("".equals (id)){
            logger.debug("返回值" );
        }else{
           depa = depaMapper.get(id);
        }
        return depa;
    }

    @Override



    public User loginAndGet(UserLoginVO userLoginVO) {
        User user = userMapper.selectByUserAccount(userLoginVO.getUserAccount());
        if (user == null || !user.getPassword().equals(userLoginVO.getPassword())) {
            return null;
        }
        return user;
    }

    @Override

    public List<Depa> getAllDepa() {
        return depaMapper.queryAll();
    }

    @Override
    public void modifyDepa(Depa depa) {
        if(depa!=null){
            if("".equals (depa.getDepaName ())&&"".equals (depa.getAddress ())){
                logger.debug("返回值" );
            }else{
                depaMapper.modify(depa);
            }
        }

    }
}
